/**
 * 页码管理器
 */
define(function(){
	var ToolPage = function(){
		this._pages = [];
		this._current_page = 0;
		
		/**
		 * 重置页码管理器
		 */
		this.reset = function(){
			this._pages = [];
			this._current_page = 0;
        }

        /**
         * 将数据插入到页码列表中
         * @param {Object} obj 要插入的数据
         */
        this.pushObj = function(obj){
			this._pages || (this._pages = []);
            this._current_page ||  (this._current_page = 0);
            this._pages[this._current_page] || (this._pages[this._current_page] = []);
            this._pages[this._current_page].push(obj);
		}
        
		/**
		 * 获取当前页码内容
		 */
        this.getCurrentPageData = function(){
			this._pages || (this._pages = []);
			this._current_page ||  (this._current_page = 0);
			return this._pages[this._current_page] || (this._pages[this._current_page] = []);
		}

		/**
         * 设置当前页码的内容
         * @param {Object} data 要设置的数据
         */
		this.setCurrentPageData = function(data){
			this._pages || (this._pages = []);
			this._current_page ||  (this._current_page = 0);
			this._pages[this._current_page] = data;
		}

		/**
		 * 将上一页内容保存到当前页
		 */
		this.saveToCurrentPage = function(){
			var prePageCount = this._current_page-1;
			if(!isNaN(prePageCount) && prePageCount >=0){
				this._pages || (this._pages = []);
				this._current_page ||  (this._current_page = 0);
				this._pages[this._current_page] = this._pages[prePageCount];
			}
		}

        /**
         * 将上一页对象内容保存到当前页
         */
		this.saveObjToCurrentPage = function(){
			var prePageCount = this._current_page-1;
			if(!isNaN(prePageCount) && prePageCount >=0){
				//for循环读取对象数据
				var prePageObjData = [];
				for(var index in this._pages[prePageCount]){
					if( this._pages[prePageCount][index].class == "DRFileRecord" ){
						prePageObjData.push(this._pages[prePageCount][index]);
					}
				}
				this._pages || (this._pages = []);
				this._current_page ||  (this._current_page = 0);
				this._pages[this._current_page] = prePageObjData;
			}
        }

        /**
         * 下一页
         * @param {Object} obj
         * @param {Object} print
         * @param {Function} win
         */
		this.nextPage = function( obj,print,win){
			this._current_page++;
			print(obj);
			(typeof win === "function") && win(obj);
		}

		/**
		 * 上一页
		 * @param {Object} obj
		 * @param {Object} print
		 * @param {Function} win
		 */
		this.prePage = function( obj,print,win ){
			( this._current_page > 0 ) && this._current_page--;
			print(obj);
			(typeof win === "function") && win(obj);
		}
	};
	return ToolPage;
});